<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script type="text/javascript" src="static/js/jquery.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-treeview.min.css"
          th:href="@{static/js/bootstrap/css/bootstrap-treeview.min.css}"
    >
    <script src="static/js/bootstrap/js/bootstrap-treeview.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.addtabs.css">
    <script src="static/js/bootstrap/js/bootstrap.addtabs.min.js"></script>
    <link rel="stylesheet" href="static//js/bootstrap/css/bootstrap-table.min.css">
    <script src="static/js/bootstrap/js/bootstrap-table.min.js"></script>
    <script src="static/js/bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="static/js/bootstrap/js/bootbox.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-datetimepicker.min.css" />
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="static/js/bootstrap-fileinput/js/fileinput.js"></script>
    <script src="static/js/bootstrap-fileinput/js/locales/zh.js"></script>
    <link rel="stylesheet" href="static/js/bootstrap-fileinput/css/fileinput.css">

</head>
<body onload="showSel()">
<input id="upUpdatePicture_ch"  type="hidden" th:value="${id.queryPriceId}">

    <br><br>
    <font size="5px" style="margin-left: 50%"><b>填写询价单信息</b></font>
    <form class="form-inline" id="myform" role="form" method="post">

        <!--<input name="productId" id="ww" th:value="${id.queryPriceId}">-->

        <table class="table">
            <thead>
            <tr>
                <td style="background-color: #afd9ee" colspan="9">
                    <font size="3">项目时间信息</font>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="form-group">
                        <label>报价开始日期：</label>
                        <td>
                             <input type="radio" value="1" onclick="aastartDate()"  name="selectQueryPriceStartDate" style="margin-left: -340px">立即开始
                             <input type="radio" value="2" onclick="aastartDate()" name="selectQueryPriceStartDate" style="margin-left: 300px">自定义开始时间：
                                <span id="span1"></span>
                             <span style="color: #ff0000" id="span_queryPriceStartDate"></span>
                        </td>

                        <tr>
                            <td colspan="3">报价截止日期：
                                <input type="date" name="queryPriceEndDate" onchange="yz_queryPriceEndDate()" id="queryPriceEndDate" class="form-control" style="margin-left: 30px">
                                <div hidden id="span_queryPriceEndDate" class="alert alert-danger">填写不正确</div>
                                <br>
                                <br>
                            </td>
                        </tr>

                        <tr>
                            <td width="500px">中标结果公布日期：
                                <input type="radio" onclick="bbstartDate()" value="1"  name="selectBiddingEndDate" style="margin-left: 30px">定标后立即发布
                            </td>

                            <td>
                                <input type="radio" onclick="bbstartDate()" value="2" name="selectBiddingEndDate" style="margin-left: 30px">自定义公布日期：
                                <span id="span2"></span>
                                <span style="color: #ff0000" id="span_biddingEndDate"></span>
                            </td>
                        </tr>

                        <tr>
                            <td>期望收货周期：
                                <input type="text" name="receiveGoodsDay" onkeyup="yz_receiveGoodsDay()" id="receiveGoodsDay" style="margin-left: 113px">&nbsp;&nbsp;天
                                <span style="color: red" id="span_receiveGoodsDay"></span>
                            </td>
                        </tr>

                        <tr>
                            <td>最低参与报价供应商的数量：
                                <input type="text" name="queryPriceCompanyCountMin" onkeyup="yz_queryPriceCompanyCountMin()" id="queryPriceCompanyCountMin" style="margin-left: 30px">&nbsp;&nbsp;个
                                <span style="color: #ff0000" id="span_queryPriceCompanyCountMin"></span>
                            </td>
                        </tr>
                    </div>
                </td>
            </tr>
            </thead>
        </table>
            <table class="table table-bordered">
                <tr>
                    <td style="background-color: #afd9ee" colspan="3">
                        <font size="3">商品及交易信息</font>
                    </td>
                </tr>

                <tr>
                    <td>预期总价：
                        <input type="text" name="expectTotal" style="margin-left: 140px">&nbsp;&nbsp;元
                    </td>
                </tr>

                <tr>
                    <td width="500px">* 配送方式：
                        <input type="radio" value="1" name="" style="margin-left: 30px">&nbsp;&nbsp;线上发货
                    </td>
                </tr>

                <tr>
                    <td width="500px">* 收货地址：
                        <input type="text" name="address" style="margin-left: 140px">&nbsp;&nbsp;
                    </td>
                </tr>

                <tr>
                    <td>
                        采购部门：<select class="selectpicker form-control" data-live-search="true" onchange="nbChr()" name="purchasingDepartmentId" id="addid"></select>
                                <select class="selectpicker form-control" data-live-search="true" onchange="nbChr2()" name="departmentOrganizationId" id="addid2"></select>
                    </td>
                </tr>

                <tr>
                    <td>
                        默认工厂：<select class="selectpicker form-control" data-live-search="true" onchange="nbChr3()" name="defaultPlant" id="addid3"></select>
                        默认库存地：<select class="selectpicker form-control" data-live-search="true" name="defaultInventory" id="addid4"></select>
                    </td>
                </tr>

                <tr>
                    <td style="background-color: #afd9ee" colspan="3">
                        <font size="3">备注信息</font>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div class="form-group">
                            <textarea name="queryPriceRemark" id="queryPriceRemark" placeholder="如有其他请求,请在此处说明" autocomplete="off" class="form-control" rows="10" cols="100%"></textarea>
                        </div>
                    </td>
                </tr>
                <tr>

                <tr>
                    <td style="background-color: #afd9ee" colspan="3">
                        <font size="3">附件</font>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <input type="file" width="500100px" id="file‐Portrait" name="queryPriceAccessory"/><br>
                        <input type="hidden" id="file" name="queryPriceAccessory"/>* 支持Png、Jpg、pdf、Word、Excel文件大小不可超过50M。
                    </td>
                </tr>
            </table>
        <br>
        <br>
        <div style="margin-left: 50px">
            <b>*您是否填写材料单：</b>
            <label class="radio-inline" style="margin-left: 15px">
                <input type="radio" name="supplyMaterial" value="1">是
            </label>
            <label class="radio-inline" style="margin-left: 50px">
                <input type="radio" name="supplyMaterial" value="2">否
            </label>
        </div>
        <br><br>
        <center>
            <button type="button" onclick="return addProduct()" class="btn btn-primary">确认发布询价单</button>
            <button type="button" class="btn btn-primary" onclick="addFindPriceChr()" style="margin-left: 50px">下一步 填写材料单</button>
            <button type="button" class="btn btn-primary" onclick="updateSelectQuerySave()" style="margin-left: 50px">修改询价信息</button>
        </center>
    </form>
    <br><br><br>

</body>
<script>



    $(function (){
        updateSelectQuery();
    })

    function bbstartDate(){
        var bb = $("input[name='selectBiddingEndDate']:checked").val();
        var span = document.getElementById("span2");
        if (bb == 2){
            span.innerHTML="<input type=\'date\' class=\'form-control\' name=\'biddingEndDate\' onchange=\'yz_biddingEndDate()\' id=\'biddingEndDate\' style=\'margin-left: 30px\'>"
        }else{
            span.innerHTML="";
        }
    }


    function aastartDate(){
        var aa = $("input[name='selectQueryPriceStartDate']:checked").val();
        var span = document.getElementById("span1");
        if (aa == 2){
           span.innerHTML="<input type=\'date\' name=\'queryPriceStartDate\' id=\'queryPriceStartDate\' class=\'form-control\' style=\'margin-left: 25px\'>"
        }else{
            span.innerHTML="";
        }
    }

    function showSel(){
        $.ajax({
            "type" : 'get',
            "url": 'getSelectClassChr',
            "dataType" : "json",
            "success" : function(data) {
                var arr = data;
                var opts = "";
                for( var i = 0 ; i < arr.length; i++ ){
                    var depart = arr[i];
                    opts += "<option value='"+depart.id+"'>"+depart.name+"</option>";
                }

                // 查询界面
                $("#addid").append(opts);
                $("#addid").selectpicker("refresh");
            }
        });
    }
    function nbChr(){
        var pid = document.getElementById("addid").value;
        $.ajax({
            "type" : 'get',
            "url": 'getSelectClassChrNb?pid='+pid,
            "dataType" : "json",
            "success" : function(data) {
                var arr = data;
                var opts = "";
                for( var i = 0 ; i < arr.length; i++ ){
                    var depart = arr[i];
                    opts += "<option value='"+depart.id+"'>"+depart.name+"</option>";
                }
                // 查询界面
                $("#addid2").append(opts);
                $("#addid2").selectpicker("refresh");
            }
        });
    }
    function nbChr2(){
        var pid = document.getElementById("addid2").value;
        $.ajax({
            "type" : 'get',
            "url": 'getSelectClassChrNb2?pid='+pid,
            "dataType" : "json",
            "success" : function(data) {
                var arr = data;
                var opts = "";
                for( var i = 0 ; i < arr.length; i++ ){
                    var depart = arr[i];
                    opts += "<option value='"+depart.id+"'>"+depart.name+"</option>";
                }
                // 查询界面
                $("#addid3").append(opts);
                $("#addid3").selectpicker("refresh");
            }
        });
    }
    function nbChr3(){
        var pid = document.getElementById("addid3").value;
        $.ajax({
            "type" : 'get',
            "url": 'getSelectClassChrNb3?pid='+pid,
            "dataType" : "json",
            "success" : function(data) {
                var arr = data;
                var opts = "";
                for( var i = 0 ; i < arr.length; i++ ){
                    var depart = arr[i];
                    opts += "<option value='"+depart.id+"'>"+depart.name+"</option>";
                }
                // 查询界面
                $("#addid4").append(opts);
                $("#addid4").selectpicker("refresh");
            }
        });
    }
    /* 图片上传 */
    $('#file‐Portrait').fileinput({
        language: 'zh', //设置语言
        uploadUrl: "upLoadChr",
        allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
        maxFileCount: 100,
        enctype: 'multipart/form‐data',
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn‐primary", //按钮样式
        previewFileIcon: "<i class='glyphicon glyphicon‐king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"

    })
    //导入文件上传完成之后的事件
    $("#file‐Portrait").on("fileuploaded", function (event, data, previewId, index) {
        console.log(data);
        console.log(data.response.requestPath)
        $("#file").val(data.response.requestPath);
    });

    /**
     * 买家新增方法
     * @returns {boolean}
     */
    function addProduct(){
        if (yz_receiveGoodsDay() & yz_queryPriceCompanyCountMin() &  yz_queryPriceStartDate() & yz_biddingEndDate()){
            $.ajax({
                url:"addProduct_Chr",
                data:$("#myform").serialize(),
                dateType:"post",
                success:function(data){
                    alert("成功")
                }
            })
            return  true;
        }
        return  false;
    }

    /* 期望收货周期 */
    function yz_receiveGoodsDay(){
        var receiveGoodsDay = $("#receiveGoodsDay").val()
        var span = $("#span_receiveGoodsDay")
        var reg = /^[0-9]{1,}$/
        if (reg.test(receiveGoodsDay)){
            span.text("")
            return true
        }else{
            span.text("请输入整数")
            return false
        }
    }
    /* 期望收货周期 */
    function yz_queryPriceCompanyCountMin(){
        var queryPriceCompanyCountMin = $("#queryPriceCompanyCountMin").val()
        var span = $("#span_queryPriceCompanyCountMin")
        var reg = /^[0-9]{1,}$/
        if (reg.test(queryPriceCompanyCountMin)){
            span.text("")
            return true
        }else{
            span.text("请输入整数")
            return false
        }
    }


    <!--  自定义开始时间  -->
    function yz_queryPriceStartDate(){
        var queryPriceStartDate = $("#queryPriceStartDate").val()
        var span = $("#span_queryPriceStartDate")
        if (queryPriceStartDate != "") {
            span.text("")
            return true
        }else{
            span.text("不能为空")
            return false
        }
    }
    <!--  自定义公布日期  -->
    function yz_biddingEndDate(){
        var biddingEndDate = $("#biddingEndDate").val()
        var span = $("#span_biddingEndDate")
        if (biddingEndDate != "") {
            span.text("")
            return true
        }else{
            span.text("不能为空")
            return false
        }
    }
    function addFindPriceChr(){
        location.href="billOfMaterials.html"
    }


    var aa = null;
    /* 修改询价单回显 */
    function updateSelectQuery() {
        var productId = $("#upUpdatePicture_ch").val()
        $.ajax({
            url: "updateSelectQuery?productId="+productId,
            success: function (data) {
                $("input[name='productId']").val(data.productId);
                $("[value="+data.queryPriceStartDate+"]").prop("checked",true);
                $("input[name='queryPriceEndDate']").val(data.queryPriceEndDate);
                $("[value="+data.biddingEndDate+"]").prop("checked",true);
                $("input[name='receiveGoodsDay']").val(data.receiveGoodsDay);
                $("[value="+data.queryPriceCompanyCountMin+"]").prop("checked",true);

                $("input[name='expectTotal']").val(data.expectTotal);
                $("input[name='address']").val(data.address);
                $("input[name='purchasingDepartmentId']").val(data.productCount);
                $("input[name='departmentOrganizationId']").val(data.productCount);
                $("input[name='defaultPlant']").val(data.productCount);
                $("input[name='defaultInventory']").val(data.productCount);
                /*$("input[name='queryPriceRemark']").val(data.queryPriceRemark);*/
                $("#queryPriceRemark").val(data.queryPriceRemark);
                // <img id="queryPriceAccessory" width="100px" height="100px" />

                $("#queryPriceAccessory").attr("src",data.queryPriceAccessory)	//赋值
                $("[value="+data.supplyMaterial+"]").prop("checked",true);
            }
        })
    }

    function updateSelectQuerySave(){
       //$("#ww").val(aa)
        $.ajax({
            url:"updateSelectQuerySave",
            data:$("#myform").serialize(),
            dateType:"post",
            success:function(data){
                $("#table").bootstrapTable("refresh")
                alert("修改成功")
            }
        })
    }
</script>
</html>